package main

import (
	"fmt"
	"os"
	
	tiff "github.com/chai2010/tiff"
)

func main() {
	// Try to access raw data directly
	filename := "./demdata/ClipResult.tif"
	file, err := os.Open(filename)
	if err != nil {
		fmt.Printf("Failed to open TIFF file: %v\n", err)
		return
	}
	defer file.Close()
	
	// Try to read raw data
	// First, let's see if we can get image info without decoding the entire image
	cfg, err := tiff.DecodeConfig(file)
	if err != nil {
		fmt.Printf("Failed to decode config: %v\n", err)
		return
	}
	
	fmt.Printf("Image config: %+v\n", cfg)
	fmt.Printf("Width: %d, Height: %d\n", cfg.Width, cfg.Height)
	
	// Try to decode just a small region
	file.Seek(0, 0)
	img, err := tiff.Decode(file)
	if err != nil {
		fmt.Printf("Failed to decode TIFF: %v\n", err)
		return
	}
	
	fmt.Printf("Successfully decoded image\n")
	fmt.Printf("Image bounds: %v\n", img.Bounds())
	fmt.Printf("Image type: %T\n", img)
	
	// Test a few pixel values
	x, y := 9361, 5669
	color := img.At(x, y)
	r, g, b, a := color.RGBA()
	fmt.Printf("Pixel at (%d, %d): R=%d, G=%d, B=%d, A=%d\n", x, y, r, g, b, a)
	
	// Try nearby pixels
	for i := -2; i <= 2; i++ {
		for j := -2; j <= 2; j++ {
			nx, ny := x+i, y+j
			if nx >= 0 && ny >= 0 && nx < img.Bounds().Dx() && ny < img.Bounds().Dy() {
				color := img.At(nx, ny)
				r, g, b, a := color.RGBA()
				fmt.Printf("Pixel at (%d, %d): R=%d, G=%d, B=%d, A=%d\n", nx, ny, r, g, b, a)
			}
		}
	}
}
